import { cloneDeep } from 'lodash'
//import { getRole } from '@/utils/users'
const filterAuthMenus = (menus) => {
  const authMenus = [] // 返回的过滤后的数据
  const role = getRole()
  menus.forEach(menu => {
    if (menu.roles === '*' || menu.roles.includes(role)) {
      // 递归调用处理children
      if (menu.children) {
        menu.children = filterAuthMenus(menu.children)
      }
      authMenus.push(menu)
    }
  })
  return authMenus
}
export default {
  namespaced: true,
  state: {
    sideMenus: [
      {
        label: '个人主页',
        path: '/dashBoard',
        icon: 'HomeFilled',
        //children:[]
      },

      {
        label: '个人资料',
        //roles: ['admin', 'a', 'b'],
        path: '/UserInfo',
        icon: 'List',
        children: [
          {
            label: '个人资料',
            path: '/profile',
          },
          {
            label: '用户银行卡',
            path: '/userbank',
          }

        ]
      },
     /*  {
        label: '账户管理',
        path: '/userbank',
        icon: 'Sell',
      }, */

      {
        label: '资金管理',
        icon: 'Sell',
        children: [
          {
            label: '账户取款',
            path: '/applywithdrawl',
          },
          {
            label: '出金记录',
            path: '/outdrawl',
          },
          {
            label: '账户入金',
            path: '/accountIn',
          },
          {
            label: '入金记录',
            path: '/depositRecord',
          },
          // {
          //   label: '转账记录',
          //   path: '/usertransferrecordindex',
          // },

        ]
      },

      {
        label: '统计&报表',
        path: '/Data',
        roles: ['a', 'b', 'admin'],
        icon: 'Setting',
        children: [
          {
            label: '订单查询',
            path: '/trades',
            roles: ['admin', 'a', 'b']
          },
         

        ]
      },
      {
        label: '消息管理',
        icon: 'Setting',
        children: [
          {
            label: '消息管理',
            path: '/CustomerMassmessage',
          },
         

        ]
      },
      {
        label: '留言反馈',
        isMenu: true,
        icon: 'Sell',
        children: [
          {
            label: '留言反馈',
            path: '/LeaveComments',
          },
        
        ]
      },

    ]
  },
  getters: {
    authMenus (state) {
      const menus = cloneDeep(state.sideMenus)
      // 过滤menus
      return filterAuthMenus(menus)
    }
  }
}
